package overload;

/**
 * @Author Stringzhua
 * @Date 2024/2/28 20:55
 * description:
 * 方法重载的注意事项和使用细节
 * 参数列表:必须不同(参数类型或个数或顺序,至少有一样不同,参数名无要求)
 * 返回类型:无要求
 */
public class overloaddetail {
    public static void main(String[] args) {
        MyCalculator01 mc = new MyCalculator01();
        System.out.println(mc.calculate(1, 2));
        System.out.println(mc.calculate(1, 1.2));
        System.out.println(mc.calculate(1.1, 2));
        System.out.println(mc.calculate(1, 2, 2));
    }
}

class MyCalculator01 {
    //两个整数的和
    public int calculate(int n1, int n2) {
        System.out.println("calculate(int n1, int n2)");
        return n1 + n2;
    }

    //看看下面是否构成重载
//    public double calculate(int a1, int a2) {
    public double calculate(int a1, double a2) {
        System.out.println("calculate(int n1, double n2)");
        return a1 + a2;
    }
//java: 已在类 overload.MyCalculator01中定义了方法 calculate(int,int)
    //没有构成重载,而是方法的重复定义
    public double calculate(double n1, int n2) {
        System.out.println("calculate(double n1, int n2)");
        return n1 + n2;
//        int res = n1 + n2;
//        没有构成方法重载
    }

    public int calculate(int n1, int n2, int n3) {
        System.out.println("calculate(int n1, int n2, int n3)");
        return n1 + n2 + n3;
    }
}
